<template>
  <div style="margin-top: 15px">
    <el-row :gutter="15">
      <el-col :span="3">
        <el-form ref="ruleForm" :model="form" :rules="rules" label-width="55px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="姓名:" prop="xm">
                <el-input v-model="form.xm" size="mini" clearable>
                  <el-button
                    slot="append"
                    size="mini"
                    icon="el-icon-search"
                    @click="search"
                  />
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="性别:">
                {{ form.xb }}
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="年龄:">
                {{ form.nl }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-table
              :data="tableData"
              style="width: 100%"
              borde
              highlight-current-row
              @current-change="handleCurrentChange"
            >
              <!-- <el-table-column type="index" width="50" label="序号" /> -->
              <el-table-column prop="xm" label="姓名" width="100" />
              <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="small"
                    @click="handleClick(scope.row, 'detail')"
                    >查看</el-button
                  >
                  <el-button
                    type="text"
                    size="small"
                    @click="handleClick(scope.row, 'edit')"
                    >编辑</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>
          <!-- <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
          </el-form-item> -->
        </el-form>
      </el-col>
      <el-col :span="21">
        <div style="margin-right: 10px">
          <el-scrollbar :style="height">
            <!-- <el-card
            class=" box-card" shadow="hover" style="height: 80%; overflow-y: scroll"> -->
            <!-- <span style="font-size: 50px"> 【FEES】吞咽障碍评估系统 </span> -->
            <evaluate
              :my-prop="evaluateModel"
              :image-list="imageList"
              @image-sent="setImage"
            />
            <!-- </el-card> -->
          </el-scrollbar>
        </div>
      </el-col>
    </el-row>
    <!-- <el-row>
      <el-col :span="24">
        <span v-for="fit in imageList" :key="fit" class="block">
          <el-image style="width: 100px; height: 100px" :src="fit" :fit="fit" />
        </span>
      </el-col>
    </el-row> -->
  </div>
</template>

<script>
import evaluate from './custom/evaluate';
import Camera from './custom/Camera.vue';
export default {
  // name: "dashboard",
  components: { evaluate, Camera },

  data() {
    return {
      height: '',
      imageList: [],
      evaluateModel: {},
      tableData: [],
      rules: {
        xm: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
      },
      form: {
        xm: '',
        xb: '',
        nl: '',
        csrq: '',
        sjrq: new Date(),
        cfz: '',
        mzh: '',
        zyh: '',
        bqh: '',
        cwh: '',
        blh: '',
        yqxh: '',
        jcys: '',
        yjh: '',
        shys: '',
        sjks: '',
        sjys: '',
        jlys: '',
        jclx: '',
        sflx: '',
        jcsf: '',
        bs: '',
        zs: '',
        mz: '',
        hy: '',
        zns: '',
        syzh: '',
        sg: '',
        tz: '',
        tbmj: '',
        dh: '',
        sfz: '',
        lbh: '',
        zy: '',
        dw: '',
        jzdz: '',
        hjdz: '',
      },
    };
  },
  created() {
    this.tableData = eval(localStorage.getItem('customer'));
  },
  mounted() {
    window.screenWidth = document.body.clientWidth;
    window.screenHeight = document.body.clientHeight;
    this.screenWidth = window.screenWidth;
    this.screenHeight = window.screenHeight;
    this.height = 'height:' + (window.screenHeight - 200) + 'px';
  },
  methods: {
    search() {},
    setImage(url) {
      this.imageList = url;
    },

    handleClick(row, goal) {
      this.$router.push({
        path: '/addCustom',
        query: { id: row.id, flag: goal },
      });
    },
    setEvaluate() {
      this.$router.push({ path: '/evaluate', query: this.form });
      // this.$router.push(`/evaluate?redirect=${this.form}`);
      // this.$router.push({
      //   name: "evaluate",
      //   params: { item: this.form },
      // });
    },
    handleCurrentChange(val) {
      this.evaluateModel = val;
      this.form = val;
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // this.$store.commit("addView", 123);
          this.$store.dispatch('customer/addVisitedView', this.form);
        } else {
          console.log('error submit!!');
        }
      });
    },
    setnl() {
      const today = new Date();
      const birthDate = new Date(this.form.csrq);
      let age = today.getFullYear() - birthDate.getFullYear();
      const m = today.getMonth() - birthDate.getMonth();
      if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
      }
      this.form.nl = age;
    },
  },
};
</script>
<style>
.box-card {
  height: 480px;
}

.el-scrollbar__wrap {
  overflow-x: inherit;
}
</style>
